import axios from 'axios'
import config from '@/../config'
import { Notification } from 'element-ui'


const request = axios.create({
  baseURL: config.baseURL,
  withCredentials: true
})

request.interceptors.request.use(
  config => {
    return config
  }, error => {
    // Do something with request error
    return Promise.reject(error)
  }
)
request.interceptors.response.use(
  res => {
    if (res.data.code != 0) {
      Notification({
        title: res.data.msg,
        type: 'warning'
      })
    }
    return res
  }, error => {
    // Do something with response error
    Notification({
      title: error.message,
      type: 'error'
    })
    console.error(error);
    // return Promise.reject(error)
  }
)

export default request

